﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RPGMapa.Data;

namespace RPGMapa.Controls
{
    public partial class MapPainter : TilePanel
    {
        private Map map;

        public Size OriginalSize
        {
            get
            {
                return new Size(
                    TileCapacity.X * TileSize.X,
                    TileCapacity.Y * TileSize.Y);
            }
        }
        public Vector2 TileCapacity
        {
            get { return map.TileNumber; }
        }
        public Vector2 TileSize
        {
            get { return map.TileSize; }
        }

        public MapPainter()
        {
            InitializeComponent();
        }

        public void Create(Map m)
        {
            map = m;
            gBackBuffer.DrawImageUnscaled(map.Layer, Point.Empty);
            gControl.DrawImageUnscaled(BackBuffer, Point.Empty);

        }

        public void ProcessTile(Tile tile, Vector2 position, Size tileSizeToDraw)
        {
            Point p = new Point(
                position.X * tileSizeToDraw.Width,
                position.Y * tileSizeToDraw.Height);

            map.DrawTile(tile.TileBitmap, position);
            map.WriteTile(tile, position);
            gBackBuffer.DrawImage(tile.TileBitmap, new Rectangle(p, tileSizeToDraw));
            gControl.DrawImageUnscaled(BackBuffer, Point.Empty);
        }
    }
}
